package com.community.web.controller.repair;

import java.util.List;

import com.community.body.domain.ZyRepair;
import com.community.body.dto.ServicemanDTO;
import com.community.body.service.IZyRepairService;
import com.community.body.vo.EchartsVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.community.common.annotation.Log;
import com.community.common.core.controller.BaseController;
import com.community.common.core.domain.AjaxResult;
import com.community.common.enums.BusinessType;
import com.community.common.core.page.TableDataInfo;

/**
 * 报修信息Controller
 * 
 * @author community
 * @date 2024-04-19
 */
@RestController
@RequestMapping("/repair/repairInfo")
public class ZyRepairController extends BaseController
{
    @Autowired
    private IZyRepairService zyRepairService;

    /**
     * 查询报修信息列表
     */
    @PreAuthorize("@ss.hasPermi('repair:repairInfo:list')")
    @GetMapping("/list")
    public TableDataInfo list(ServicemanDTO servicemanDTO)
    {
        startPage();
        List<ServicemanDTO> list = zyRepairService.selectZyRepairList(servicemanDTO);
        return getDataTable(list);
    }

    @GetMapping("/rate")
    public TableDataInfo getRepairRate(ServicemanDTO servicemanDTO){
        List<EchartsVo> list = zyRepairService.getRepairRate(servicemanDTO);
        return getDataTable(list);
    }

    /**
     * 分配维修人员
     */
    @PreAuthorize("@ss.hasPermi('repair:repairInfo:serviceman')")
    @GetMapping("/serviceman")
    public TableDataInfo serviceman(ServicemanDTO servicemanDTO)
    {
        startPage();
        List<ServicemanDTO> list = zyRepairService.selectZyRepairServiceman(servicemanDTO);
        return getDataTable(list);
    }

//    /**
//     * 导出报修信息列表
//     */
//    @PreAuthorize("@ss.hasPermi('repair:repairInfo:export')")
//    @Log(title = "报修信息", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, ZyRepair zyRepair)
//    {
//        List<ZyRepair> list = zyRepairService.selectZyRepairList(zyRepair);
//        ExcelUtil<ZyRepair> util = new ExcelUtil<ZyRepair>(ZyRepair.class);
//        util.exportExcel(response, list, "报修信息数据");
//    }

    /**
     * 获取报修信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('repair:repairInfo:query')")
    @GetMapping(value = "/{repairId}")
    public AjaxResult getInfo(@PathVariable("repairId") Long repairId)
    {
        return success(zyRepairService.selectZyRepairByRepairId(repairId));
    }

    /**
     * 新增报修信息
     */
    @PreAuthorize("@ss.hasPermi('repair:repairInfo:add')")
    @Log(title = "报修信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZyRepair zyRepair)
    {
        return toAjax(zyRepairService.insertZyRepair(zyRepair));
    }

    /**
     * 修改报修信息
     */
    @PreAuthorize("@ss.hasPermi('repair:repairInfo:edit')")
    @Log(title = "报修信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZyRepair zyRepair)
    {
        return toAjax(zyRepairService.updateZyRepair(zyRepair));
    }

    /**
     * 删除报修信息
     */
    @PreAuthorize("@ss.hasPermi('repair:repairInfo:remove')")
    @Log(title = "报修信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{repairIds}")
    public AjaxResult remove(@PathVariable Long[] repairIds)
    {
        return toAjax(zyRepairService.deleteZyRepairByRepairIds(repairIds));
    }
}
